package com.lry.util.requestcore;

import cn.hutool.cache.CacheUtil;
import cn.hutool.cache.impl.TimedCache;

/**
 * @author ALI
 * @since 2023/5/16
 */
public class TokenCache {

    private static final TimedCache<String, String> CACHE = CacheUtil.newTimedCache(3600000);

    public static void add(String url, String token) {
        CACHE.put(getPre(url), token);
    }

    public static String get(String url) {
        return CACHE.get(getPre(url));
    }

    private static String getPre(String url) {
        if (!url.contains("//")) {
            return url;
        }
        return url.substring(0, url.indexOf("/", url.indexOf("//") + 2));
    }
}
